package mapObjects;
import mapData.Coord;

/*
 * projectiles should be stored in some arraylist. 
 * after updating all, find those w/ hit = true
 * if so, remove them from list and deal damage accordingly
 */ 

public abstract class Projectile
{
    protected int spd;
    protected int dmg;
    protected int facing;
    
    //for use w/ facing
    public static final int NORTH = 0;
    public static final int EAST = 1;
    public static final int SOUTH = 2;
    public static final int WEST = 3;
    
    protected int targetDist;
    protected Coord curr;
    protected boolean hit = false; // hit when targetDist = 0
    protected boolean hitAnythingInPath; //if true, projectile will stop at the first thing that is in its path
    
    public void update()
    {
        if(!hit)
        {
            move();
        }
        
    }
    
    public boolean isDone()
    {
        return hit;
    }
    
    
    
    private void move()
    {
        if(spd<=targetDist)
        {
            updateDist(spd);
        }
        else
        {
            updateDist(targetDist);
        }
        
        if(targetDist == 0)
        {
            hit = true;
        }
    }
    
    private void updateDist(int distTravel)
    {
        targetDist -= distTravel;
        int x = curr.getX();
        int y = curr.getY();
        if(facing == 0)
        {
            curr.setY(y-distTravel);
        }
        else if(facing == 1)
        {
            curr.setX(x+distTravel);
        }
        else if(facing == 2)
        {
            curr.setY(y+distTravel);
        }
        else if(facing == 3)
        {
            curr.setX(x-distTravel);
        }
        else
        {
            System.out.println("no such facing");
            System.exit(1);
        }
    }  
}
